<template>
	<view>

		<view v-if="is_style=='img'" @click="app_apple_login">
			<image class="q_y login_icon" src="@/static/icon/apple.png">
			</image>
		</view>
	</view>
</template>

<script>
	export default {
		name: "login-mp-ali",
		props: {
			userName: {
				type: String,
				default: ''
			},
			avatarUrl: {
				type: String,
				default: ''
			},
			agr: {
				type: Boolean,
				default: false
			},
			agr: {
				type: Boolean,
				default: false
			},
			is_style: {
				type: String,
				default: 'button'
			},
		},
		data() {
			return {}
		},
		created() {
			this.face = this.avatarUrl;
			this.nickname = this.userName;
		},
		methods: {

			app_apple_login() {
				let that = this;
				if (!this.agr) {
					uni.showToast({
						title: '请勾选同意协议',
						icon: "none"
					});
					return;
				}
				uni.showLoading({
					title: '正在连接...'
				})
				uni.login({
					provider: 'apple',
					success: function(loginRes) {
						// 登录成功  
						uni.getUserInfo({
							provider: 'apple',
							success(res) {
								// 获取用户信息成功
								console.log(res)
								var userInfo = res.userInfo;
								var code = res.code;
								let requestParams = {
									userInfo: JSON.stringify(userInfo),
									face: that.avatarUrl,
									nickname: that.userName,
									sex: that.sex,
								};
								that.Banmikeji.app_Apple_login(requestParams).then(ret => {
									that.$emit('confirm', ret);
								})

							}
						})
					},
					fail: function(err) {
						 uni.hideLoading()
					}
				});
			},



		}
	}
</script>
<style lang="scss">
	.but_login {
		width: 600rpx;
		height: 80rpx;
		background-color: #1DC069;
	}

	button::after {
		border: none;
	}

	button {

		border: 0;
		padding: 0;
		background-color: transparent;

	}
</style>